#define _CRT_SECURE_NO_WARNINGS
#include"impleinn.h"

void initial(Que* qu)
{
	assert(qu);
	qu->head = qu->tail = NULL;
	qu->size = 0;
}

void destory(Que* qu)
{
	LTeam* node = qu->tail;
	while (qu->tail != qu->head)
	{
		LTeam* next = qu->head->next;
		free(qu->head);
		qu->head = next;
	}
	free(node);
	free(qu);
	node = NULL;
	qu = NULL;
}

void pushlteam(Que* qu, LTdata x)
{
	assert(qu);
	LTeam* newnode = (LTeam*)malloc(sizeof(LTeam));
	if (newnode == NULL)
	{
		perror("malloc error");
		return;
	}
	newnode->data = x;
	if (qu->tail == NULL)
	{
		newnode->next = NULL;
		qu->head = qu->tail = newnode;
	}
	else
	{
		newnode->next = qu->tail->next;
		qu->tail->next = newnode;
		qu->tail = newnode;
	}
	qu->size++;
}

void poplteam(Que* qu)
{
	assert(qu);
	assert(!judgeempty(qu));
	//LTeam* eam = qu->tail;
	if (qu->tail == qu->head)
	{
		free(qu->tail);
		qu->tail = NULL;
		qu->head = NULL;

	}
	else
	{
		LTdata* next1 =qu-> head;
		qu->head = qu->head->next;
		free(next1);
		next1 = NULL;
	}
	qu->size--;
	//free(eam);
	//eam = NULL;
}

LTdata gettail(Que* qu)
{
	assert(qu);
	assert(!judgeempty(qu));
	return qu->tail->data;
}

LTdata getfront(Que* qu)
{
	assert(qu);
	assert(!judgeempty(qu));
	return qu->head->data;
}

bool judgeempty(Que* qu)
{
	assert(qu);
	return qu->tail == NULL && qu->head == NULL;
}

int LTeamsize(Que* qu)
{
	assert(qu);
	assert(!judgeempty(qu));
	return qu->size;
}